<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    const data = [
        {state: "3", start: "2023-06-29 09:20:22", end: "2023-06-29 09:46:22"},
        {state: "3", start: "2023-06-29 10:11:52", end: "2023-06-29 10:48:52"},
        {state: "1", start: "2023-06-29 13:13:14", end: "2023-06-29 13:31:58"},
        {state: "1", start: "2023-06-29 10:49:22", end: "2023-06-29 11:09:52"},
        {state: "3", start: "2023-06-29 13:34:58", end: "2023-06-29 13:45:28"},
        {state: "3", start: "2023-06-29 13:51:22", end: "2023-06-29 13:56:00"},
        {state: "1", start: "2023-06-29 13:56:14", end: "2023-06-29 14:00:01"},
        {state: "3", start: "2023-06-29 14:00:28", end: "2023-06-29 14:10:58"},
        {state: "1", start: "2023-06-29 14:22:50", end: "2023-06-29 14:26:58"},
        {state: "3", start: "2023-06-29 14:51:58", end: "2023-06-29 15:34:58"},
        {state: "3", start: "2023-06-29 15:41:23", end: "2023-06-29 15:49:58"},
        {state: "1", start: "2023-06-29 15:53:28", end: "2023-06-29 16:16:28"},
        {state: "1", start: "2023-06-29 16:44:58", end: "2023-06-29 16:50:58"}
    ];

    const result = data.reduce((acc, cur) => {
        const duration = new Date(cur.end) - new Date(cur.start);
        acc[cur.state] = (acc[cur.state] || 0) + duration / 3600 / 1000;
        return acc;
    }, {});

    console.log(result);

    console.log(Object.keys(result))


    let time1 = 0
    let time2 = 0
    let time3 = 0

    if (Object.keys(result).includes('1')) {
        time1 = (result['1']).toFixed(2)
    }


    if (Object.keys(result).includes('2')) {
        time2 = result['2'].toFixed(2)
    }

    if (Object.keys(result).includes('3')) {
        time3 = result['3'].toFixed(2)
    }

    console.log(time1, time2, time3)

    let data2 = data.sort((x,y)=>x.start - y.start)
    console.log('sort:',data2)

</script>
</body>
</html>
